<%@ page pageEncoding="UTF-8"%>
<%@ page contentType="text/html; charset=UTF-8"%>
<%@taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<% response.setHeader("Pragma","No-cache"); response.setHeader("Cache-Control","no-cache"); response.setDateHeader("Expires", 0);%>
<html lang="en">

<head>
	<meta charset="UTF-8">
	<title>添加/编辑用户</title>
	<link href="${pageContext.request.contextPath}/views/js/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
	<link href="${pageContext.request.contextPath}/views/js/ligerUI/skins/ligerui-icons.css" rel="stylesheet" type="text/css" />
	<script type="text/javascript" src="${pageContext.request.contextPath}/views/js/libs/jquery-1.6.min.js"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath}/views/js/libs/jquery.form.js"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath}/views/js/md5.js"></script>
	<script src="${pageContext.request.contextPath}/views/js/ligerUI/js/core/base.js" type="text/javascript"></script>
	<script src="${pageContext.request.contextPath}/views/js/ligerUI/js/plugins/ligerDialog.js" type="text/javascript"></script>
	<style type="text/css">
		.fl{
			float: left;
		}
		.file {
			margin-top: 30px;
		}
		.file p{
			font-size: 12px;
			line-height: 30px;
			color: #666;
			margin-bottom: 10px;
		}
		.file td{
		    height: 50px;
		    font-size: 14px;
		    font-family:"微软雅黑";
		}
		.file td input,.file td select{
			height:30px;
			line-height:30px;
			width:180px;
			color: #666;
			font-size: 14px;
			font-family:"微软雅黑";
			padding: 0 5px;
		}
		.file td input.select_trench{
			width:75px;
			height:30px;
			line-height:20px;
			margin:0;
			padding:0;
		}
		.file td input.radio01{
			width:14px;
			height:14px;
			margin:0;
			padding:0;
			float:left;
			margin-top:4px;
			margin-top:0\9;
		}
		.file td span{
			float:left;
			margin-right:15px;
			padding-left:3px;
		}
		.file div{
			height: 20px;
		}
		.file input[type=file] {
			background: #f0f0f0;
		}
		#ifopen{
			margin-top: 18px;
			margin-top: 13px \0;
			*margin-top: 13px;
		}
		.file .label_check{
			height: 50px;
			line-height: 50px;
		}
		.file div label{
			margin-left: 6px;
			color: #666;
			font-size: 12px;
		}
		.file .upload_btn {
			width: 230px;
			height: 40px;
			line-height: 30px;
			background: #00afc0;
			color: #fff;
			outline: none;
			border: none;
			margin-top:35px;
		}
	</style>
</head>

<body>
	<form id="resetpwd" action="${pageContext.request.contextPath }/user/saveoredituser" method="post" method="post">
		<input type="hidden" name="id" value="${user.id}"/>
		<table align="center" class="file" width="350">
			<tr>
				<td align="left" valign="middle" width="150">用户名称：</td>
				<td align="left" valign="middle" width="250">
					<input id="username" name="username" value="${user.username}"/>
				</td>
			</tr>
			<tr>
				<td align="left" valign="middle">手机号：</td>
				<td align="left" valign="middle">
					<input id="mobile" name="mobile" id="mobile" value="${user.mobile}"/>		
				</td>
			</tr>
			<tr>
				<td align="left" valign="middle">所属角色：</td>
				<td align="left" valign="middle">
					<select name="role" onchange="checkrole();" id="role">
						<option 
						<c:if test='${user.role == 0 }'>selected="selected"</c:if>
						 value="0">
							普通用户
						</option>
						<option 
						<c:if test='${user.role == 1 }'>selected="selected"</c:if>
						 value="1">
							部门管理员
						</option>
						<c:if test="${userRole == 3}">
							<option 
							<c:if test='${user.role == 3 }'>selected="selected"</c:if>
							 value="3">
							超级管理员
						</option>
						</c:if>
					</select>		
				</td>
			</tr>
			<c:if test="${userRole == 3}"><!-- 超级管理员选择部门 -->
				<tr id="choosedep">
					<td align="left" valign="middle">所属部门：</td>
					<td align="left" valign="middle">
						<input id="departmentName" value="${user.department.title }">
						<input id="selDepartId" name="selDepartId" type="hidden" value="${user.departmentId}">
					</td>
					<td><input class="select_trench" type="button" value="选择部门" onclick="f_open();"></td>
				</tr>
			</c:if>
			<tr>
				<td align="left" valign="middle">状态：</td>
				<td align="left" valign="middle">
					<input class="radio01" type="radio" name="status" value="1" 
					<c:if test="${user.status == 1 || user.status == null}">
						checked="checked"
					</c:if>
					/><span>启用</span>
					<input class="radio01" type="radio" name="status" value="0"
					<c:if test="${user.status == 0 }">
						checked="checked"
					</c:if>
					/><span>停用</span>
				</td>
			</tr>
			<tr>
				<td colspan="2" align="center">
					<input class="upload_btn" type="button" value="保存" onclick="saveoredit();" />
				</td>
			</tr>
		</table>
	</form>
</body>
<script type="text/javascript">
	function saveoredit(){
		var userRole = "${userRole}"
		var username = $.trim($("#username").val());
		if(username.length < 1){
			operationTips("请输入用户名称");
			return false;
		}
		var mobile = $.trim($("#mobile").val());
		//验证手机号
		var phone_verify = /^1[3|4|5|7|8][0-9]\d{8}$/;
		//手机号
		if(phone_verify.test(mobile) == false) {
			operationTips("请输入正确的手机号");
			return false;
		}
		var selrole = $('#role').val();
		var selDepartId = $.trim($("#selDepartId").val())
		if(userRole == 3 && selrole != 3){
			if(selDepartId.length < 1){
				operationTips("请选择部门");
				return false;
			}
		}
		//ajax提交表单
		var option = {
			//url:"",//如果不定义url，就是用使用要提交的表单的action，如果定义了url那么就把表单中的action覆盖了
			//type:"post",//如果要提交的表单中已经提供了请求方法那就不要在这里定义了
			dataType:"json",
			async:false,
			success:function(res){
				if(res.code == 0){
					parent.$.ligerDialog.close();
					parent.operationTips('保存成功！');
					parent.reload()
				}else if(res.code == 1){
					operationTips(res.msg);
				}else{
					parent.operationTips('保存失败！');
				}
			},
			error:function(){
				operationTips('系统繁忙，请稍后重试！');
			}
					
		}
		$("#resetpwd").ajaxSubmit(option);
		
	}

	//操作提示
	function operationTips(content){
		$.ligerDialog.alert(content);
	}
	
	
	function f_open()
    {
        $.ligerDialog.open({
            height:500,
            width: 360,
            title : '请选择部门',
            url: '${pageContext.request.contextPath}/user/todeparttreepage', 
            showMax: false,
            showToggle: true,
            showMin: false,
            isResize: true,
            slide: false,
            data: {
                name: $("#txtValue").val()
            },
            //自定义参数
            myDataName: $("#txtValue").val()
        });
    } 
    
    
    function setDepart(id,name,level){
    	 	$('#selDepartId').val(id);
    	 	$('#departmentName').val(name);
    	 	
    }
    
  //选择部门的时候
  	checkrole();
    function checkrole(){
    	var selrole = $('#role').val();
    	//如果是超级管理员的话就隐藏掉
    	if(selrole=='3'){
    		$('#choosedep').hide();
    	}else{
    		$('#choosedep').show();
    	}
    	
    }
</script>

</html>